package com.wisdytech.linkdcs.factory.service.impl;

import com.wisdytech.linkdcs.factory.model.Area;
import com.wisdytech.linkdcs.factory.model.Factory;
import com.wisdytech.linkdcs.factory.model.ProductionLine;
import com.wisdytech.linkdcs.factory.model.Shop;
import com.wisdytech.linkdcs.factory.service.*;
import com.wisdytech.linkdcs.factory.vo.FactoryModelResultVO;
import com.wisdytech.linkdcs.factory.vo.FactoryModelSearchVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service("factoryModelCommonService")
@Transactional
public class FactoryModelCommonServiceImpl implements IFactoryModelCommonService{


    @Resource
    private TmFactoryService tmFactoryService;

    @Resource
    private TmProductionLineService tmProductionLineService;

    @Resource
    private TmShopService tmShopService;

    @Resource
    private TmAreaService tmAreaService;

    @Override
    public FactoryModelResultVO getFactoryModelResult(FactoryModelSearchVO searchVO) {
        FactoryModelResultVO resultVO = new FactoryModelResultVO();
        if(searchVO == null) return resultVO;
        if(StringUtils.isNotBlank(searchVO.getFactoryId())) {
            Factory factory = tmFactoryService.getFactoryById(searchVO.getFactoryId());
            resultVO.setFactoryName(factory!=null?factory.getFactoryName():"");
        }
        if(StringUtils.isNotBlank(searchVO.getLineId())) {
            ProductionLine productionLine = tmProductionLineService.getProductById(searchVO.getLineId());
            resultVO.setLineName(productionLine!=null?productionLine.getLineName():"");
        }
        if(StringUtils.isNotBlank(searchVO.getShopId())) {
            Shop shop = tmShopService.getShopById(searchVO.getShopId());
            resultVO.setShopName(shop!=null?shop.getShopName():"");
        }
        if(StringUtils.isNotBlank(searchVO.getLocationId())) {
            Area area = tmAreaService.getAreaById(searchVO.getLocationId());
            resultVO.setLocationName(area!=null?area.getAreaName():"");
        }
        return resultVO;
    }
}
